<?php
class BbsController extends CController {
	public $defaultAction = 'hot';
	
	public function filters() {
		return array(
				'accessControl'
		);
	}
	
	
	public function accessRules() {
		return array(
			array(
				'allow',
				'expression' => ForumMembers::isAdmin()
			),
			array(
				'deny',
			),
		);
	}
	
	public function actionHot() {
		$optionName = 'hotThreads';
		$option = Options::model()->findOptionByName($optionName);
		if(isPost()) {
			$option->optionValue = implode(',', Options::filterCommaValue($_POST[$optionName]));
			if($option->save()) {
				Yii::app()->cache->set('hotThreadsWidget', $this->createWidget('HotThreads')->renderContent(true));
			}
		}
		$hotThreadsIds = explode(',', $option->optionValue);
		$threads = Threads::model()->findAllByPk($hotThreadsIds);

		$this->render('hot-threads', array('threads' => $threads, 'hotThreadsIds' => $hotThreadsIds, 'option' => $option));
	}
	
	public function actionLiteral() {
		$optionName = 'literalIds';
		$option = Options::model()->findOptionByName($optionName);
		if(isPost()) {
			$option->optionValue = implode(',', Options::filterCommaValue($_POST[$optionName]));
			if($option->save()) {
				Yii::app()->cache->set('literalWidget', $this->createWidget('Literal')->renderContent(true));
			}
		}
		$literalIds = explode(',', $option->optionValue);
		$threads = Threads::model()->findAllByPk($literalIds);

		$this->render('literal', array('threads' => $threads, 'literalIds' => $literalIds, 'option' => $option));
		
	}
}